﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace version_updater
{
    class app_config
    {
        private app_config() { }

        //---------------------------------------------------------------------------
        public static int major
        {
            get
            {
                Configuration conf = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
                return int.Parse(conf.AppSettings.Settings["major"].Value);
            }

            set
            {
                Configuration conf = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
                conf.AppSettings.Settings["major"].Value = value.ToString();
                conf.Save();
            }
        }
        //---------------------------------------------------------------------------
        public static int minor
        {
            get
            {
                Configuration conf = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
                return int.Parse(conf.AppSettings.Settings["minor"].Value);
            }

            set
            {
                Configuration conf = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
                conf.AppSettings.Settings["minor"].Value = value.ToString();
                conf.Save();
            }
        }
        //---------------------------------------------------------------------------
        public static int build
        {
            get
            {
                Configuration conf = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
                return int.Parse(conf.AppSettings.Settings["build"].Value);
            }

            set
            {
                Configuration conf = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
                conf.AppSettings.Settings["build"].Value = value.ToString();
                conf.Save();
            }
        }
        //---------------------------------------------------------------------------
        public static int revision
        {
            get
            {
                Configuration conf = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
                return int.Parse(conf.AppSettings.Settings["revision"].Value);
            }

            set
            {
                Configuration conf = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
                conf.AppSettings.Settings["revision"].Value = value.ToString();
                conf.Save();
            }
        }
        //---------------------------------------------------------------------------
        public static string root
        {
            get
            {
                return ConfigurationManager.AppSettings["root"];
            }

            set
            {
                Configuration conf = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
                conf.AppSettings.Settings["root"].Value = value;
                conf.Save();
            }
        }
        //---------------------------------------------------------------------------
        public static string version
        {
            get
            {
                return string.Format("{0}.{1}.{2}.{3}", major, minor, build, revision);
            }
        }
        //---------------------------------------------------------------------------
    }
}